//
//  ExperienceDetailViewController.m
//  BTRIP
//
//  Created by johnbk on 15/11/14.
//  Copyright © 2015年 johnbk. All rights reserved.
//

#import "ExperienceDetailViewController.h"
#import <SDWebImageManager.h>
#import <UIImageView+WebCache.h>
@interface ExperienceDetailViewController ()<UIScrollViewDelegate>

@end

@implementation ExperienceDetailViewController
-(void)dealloc{
	[_buttonOfLike release];
	[_imgView release];
	[_buttonOfReturn release];
	[_buttonOfShare release];
	[_experienceModel release];
	[_webView release];
	[_naviView release];
	[super dealloc];
}
- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
	[self interperateData];
	[self createNaviView];
}
- (void)interperateData{
	self.webView = [[UIWebView alloc]initWithFrame:CGRectMake(0, -20, self.view.frame.size.width, self.view.frame.size.height + 20)];
	[self.view addSubview:self.webView];
	[self.webView release];
	[self.webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:self.experienceModel.detail_url]]];
	self.webView.scrollView.delegate = self;
	self.webView.scalesPageToFit = YES;
	UIImageView *imView = [[UIImageView alloc]initWithFrame:self.webView.frame];
	imView.alpha = 0;
	self.webView.scrollView.bounces = NO;
	[self.view addSubview:imView];
	[imView release];
	
	
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/
- (void)viewWillAppear:(BOOL)animated{
	[self.navigationController.navigationBar setHidden:YES];
}

- (void)createNaviView{
	self.naviView = [[UIView alloc]initWithFrame:CGRectMake(0, -20, self.view.frame.size.width, 84)];
	[self.view addSubview:self.naviView];
	[self.naviView release];
	self.naviView.alpha = 0;
	self.imgView = [[UIImageView alloc]initWithFrame:self.naviView.bounds];
	[self.imgView sd_setImageWithURL:[NSURL URLWithString:self.experienceModel.url] placeholderImage:[UIImage imageNamed:@"background"]];
	[self.naviView addSubview:self.imgView];
	[self.imgView release];
	
	self.buttonOfReturn = [UIButton buttonWithType:UIButtonTypeCustom];
	self.buttonOfReturn.frame = CGRectMake(20, 35, 20, 20);
	[self.buttonOfReturn addTarget:self action:@selector(backToFront:) forControlEvents:UIControlEventTouchUpInside];
	[self.buttonOfReturn setBackgroundImage:[UIImage imageNamed:@"iconfont-fanhui-4"] forState:UIControlStateNormal];
	[self.view addSubview:self.buttonOfReturn];
	
	self.buttonOfLike = [UIButton buttonWithType:UIButtonTypeCustom];
	self.buttonOfLike.frame = CGRectMake(self.view.frame.size.width - 100, self.buttonOfReturn.frame.origin.y, self.buttonOfReturn.frame.size.width, self.buttonOfReturn.frame.size.height);
	[self.buttonOfLike setBackgroundImage:[UIImage imageNamed:@"iconfont-xin"] forState:UIControlStateNormal];
	[self.view addSubview:self.buttonOfLike];
	
	self.buttonOfShare = [UIButton buttonWithType:UIButtonTypeCustom];
	self.buttonOfShare.frame = CGRectMake(self.buttonOfLike.frame.origin.x + 20 + self.buttonOfLike.frame.size.width, self.buttonOfReturn.frame.origin.y, self.buttonOfReturn.frame.size.width, self.buttonOfReturn.frame.size.height);
	[self.buttonOfShare setBackgroundImage:[UIImage imageNamed:@"iconfont-share-3"] forState:UIControlStateNormal];
	[self.view addSubview:self.buttonOfShare];
	
}
- (void)backToFront: (UIButton *)button{
	[self.navigationController popViewControllerAnimated:YES];
}
- (void)scrollViewDidScroll:(UIScrollView *)scrollView{
	//NSLog(@" x = %f", scrollView.contentOffset.x);
	//NSLog(@" y = %f", scrollView.contentOffset.y);
	
	if (scrollView.contentOffset.y < 0) {
		[self.buttonOfShare setBackgroundImage:[UIImage imageNamed:@"iconfont-share-3"] forState:UIControlStateNormal];
		[self.buttonOfLike setBackgroundImage:[UIImage imageNamed:@"iconfont-xin"] forState:UIControlStateNormal];
		[self.buttonOfReturn setBackgroundImage:[UIImage imageNamed:@"iconfont-fanhui-4"] forState:UIControlStateNormal];
		self.naviView.alpha = 0;
	}
	else if (scrollView.contentOffset.y > 0 && scrollView.contentOffset.y < 250) {
		self.naviView.alpha = scrollView.contentOffset.y / 250;
		[self.buttonOfLike setBackgroundImage:[UIImage imageNamed:@"iconfont-xin-2"] forState:UIControlStateNormal];
		[self.buttonOfReturn setBackgroundImage:[UIImage imageNamed:@"iconfont-fanhui-3"] forState:UIControlStateNormal];
		[self.buttonOfShare setBackgroundImage:[UIImage imageNamed:@"iconfont-share-2"] forState:UIControlStateNormal];
	}
	else{
		//self.naviView.backgroundColor = [UIColor whiteColor];
		self.naviView.alpha = 1;
		[self.buttonOfLike setBackgroundImage:[UIImage imageNamed:@"iconfont-xin-2"] forState:UIControlStateNormal];
		[self.buttonOfReturn setBackgroundImage:[UIImage imageNamed:@"iconfont-fanhui-3"] forState:UIControlStateNormal];
		[self.buttonOfShare setBackgroundImage:[UIImage imageNamed:@"iconfont-share-2"] forState:UIControlStateNormal];
	}
	
	
	
}
@end
